﻿using Nop.Core.Domain.Customers;
using System;
using System.Linq;
using System.Text;

namespace Nop.Core.Domain.Logistics
{
    public class LogisticsCourier : BaseEntity
    {
        public virtual Customer Customer { get; set; }

        public int? DistrictId { get; set; }

        public string DistrictIdsString { get; set; }

        public int[] DistrictIds
        {
            get 
            {
                if (DistrictId.HasValue)
                {
                    return new int[] { DistrictId.Value };
                }
                else if (String.IsNullOrWhiteSpace(DistrictIdsString))
                {
                    return new int[0];
                }

                return DistrictIdsString.Split(',').Select(x => int.Parse(x)).ToArray();
            }
            set
            {
                if (value == null | value.Length == 0)
                {
                    DistrictIdsString = "";
                }
                else if (value.Length == 1)
                {
                    DistrictId = value[0];
                    DistrictIdsString = null;
                }
                else
                {
                    DistrictId = null;
                    DistrictIdsString = String.Join(",", value);
                }
            }
        }
    }
}
